﻿# CMakeList.txt: 在此处包括源代码并定义
# 项目特定的逻辑。
#

# 将源代码添加到此项目的可执行文件。

project(test)

# 启用递归查找
file(GLOB_RECURSE PROJECT_CPP
    RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}   # 相对于当前源目录
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"    # 包含当前目录及子目录下的所有 .cpp 文件
    "${CMAKE_CURRENT_SOURCE_DIR}/*.c"      # 包含当前目录及子目录下的所有 .c 文件
    "${CMAKE_CURRENT_SOURCE_DIR}/*.cc"     # 包含当前目录及子目录下的所有 .cc 文件
)

# 输出可执行文件
add_executable(${PROJECT_NAME} ${PROJECT_CPP})

# 导入头文件
target_include_directories(${PROJECT_NAME}
     PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
     PUBLIC "${SERVER_ROOT_DIR}/src/"
     PUBLIC "${SERVER_ROOT_DIR}/3rd/include/"
)

if(WIN32)
    # 导入库文件
    target_link_libraries(${PROJECT_NAME}
        "${SERVER_ROOT_DIR}/bin/win/breaking.lib"
    )

else()

    set_target_properties(${PROJECT_NAME} PROPERTIES
        COMPILE_FLAGS "-pthread"
        LINK_FLAGS "-pthread"
    )

    # 导入库文件
    target_link_libraries(${PROJECT_NAME}
        -Wl,--start-group
        "${SERVER_ROOT_DIR}/bin/linux/libbreaking.a"
        -Wl,--end-group
    )

    # 提取调试文件
    add_custom_command(
        TARGET  ${PROJECT_NAME}
        POST_BUILD 
        COMMAND objcopy --only-keep-debug $<TARGET_FILE:${PROJECT_NAME}> $<TARGET_FILE:${PROJECT_NAME}>.dbg
        COMMAND objcopy --strip-debug $<TARGET_FILE:${PROJECT_NAME}>
        COMMAND objcopy --add-gnu-debuglink=$<TARGET_FILE:${PROJECT_NAME}>.dbg $<TARGET_FILE:${PROJECT_NAME}>
    )
endif()

# 如果Cmake版本大于3.12, 启用C++20
if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
endif()

